package com.asia.algorithmcode.str;

import com.sun.xml.internal.org.jvnet.mimepull.CleanUpExecutorFactory;

/**
 * @DESCRIPTION: 125 、 验证回文串
 * @USER: wanfu
 * @DATE: 2025/6/10 星期二 14:32
 */
public class IsPalindrome {

    public static void main(String[] args) {
        String s = " ";
        System.out.println(isPalindrome(s));
    }


    public static boolean isPalindrome(String s) {
        int length = s.length();
        if (length == 1) {
            return true;
        }
        StringBuilder strBuilder = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            if ((s.charAt(i) >= 'A' && s.charAt(i) <= 'Z')
                    || (s.charAt(i) >= 'a' && s.charAt(i) <= 'z')
                    || (s.charAt(i) >= '0' && s.charAt(i) <= '9')) {
                strBuilder.append(s.charAt(i));
            }
        }

        s = strBuilder.toString().toLowerCase();
        int left = 0;
        int right = s.length() - 1;

        while (left < right) {
            if (s.charAt(left) != s.charAt(right)) {
                return false;
            }
            left++;
            right--;
        }
        return true;
    }

}
